package com.ssx.cloud.controller;

import com.ssx.cloud.service.HystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Package com.ssx.cloud.controller
 * @ClassName HystrixController
 * @Copyright: Copyright (c) 2020
 * @Date 2020/11/22 14:22
 * @Company www.sudaoxi.com.cn
 * @Author 苏道羲
 * @Version 1.0
 * @Description
 */
@RestController
@Slf4j
//@DefaultProperties(defaultFallback = "global_fallbackMethod")
public class HystrixController {
    @Resource
    private HystrixService hystrixService;

    @GetMapping("/consumer/hystrix/ok/{id}")
    public String paymentinfo_OK(@PathVariable("id") Integer id) {
        return hystrixService.paymentinfo_OK(id);
    }

    @GetMapping("/consumer/hystrix/timeout/{id}")
//    @HystrixCommand(fallbackMethod = "paymentinfo_TimeoutHandler",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
//    })
//    @HystrixCommand
    public String paymentinfo_Timeout(@PathVariable("id") Integer id) {
        return hystrixService.paymentinfo_Timeout(id);
    }

    public String paymentinfo_TimeoutHandler(Integer id) {
        return "这里是消费者，线程池： " + Thread.currentThread().getName()
                + "运行超时或运行出错，请稍后再试 ,id: " + id + "\t" + "o(╥﹏╥)o";
    }

    public String global_fallbackMethod() {
        return "全局异常处理处，请稍后再试,o(╥﹏╥)o";
    }
}
